package com.boge.auth.controller.dept;

import com.boge.auth.dto.SysDeptLevelDto;
import com.boge.auth.param.SysDeptParam;
import com.boge.auth.service.SysTreeService;
import com.boge.auth.service.dept.SysDeptService;
import com.boge.auth.serviceImpl.SysTreeServiceImpl;
import com.boge.auth.serviceImpl.dept.SysDeptServiceImpl;
import com.boge.core.common.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Controller
@RequestMapping("/sys/dept")
@Transactional
public class SysDeptController {

    @Resource
    SysDeptServiceImpl sysDeptService;

    @Resource
    SysTreeServiceImpl sysTreeService;

    @RequestMapping("/page.page")
    public String page() {
        return "auth/dept/dept";
    }

    @RequestMapping("/save.json")
    @ResponseBody
    public AjaxResult saveDept(SysDeptParam sysDeptParam) {
        sysDeptService.addSysDept(sysDeptParam);
        return new AjaxResult();
    }

    @RequestMapping("/tree.json")
    @ResponseBody
    public AjaxResult tree() {
        List<SysDeptLevelDto> dtoList = sysTreeService.getSysDeptTree();
        return new AjaxResult(dtoList);
    }

    @RequestMapping("/update.json")
    @ResponseBody
    public AjaxResult updateDept(SysDeptParam sysDeptParam) {
        sysDeptService.updateSysDept(sysDeptParam);
        return new AjaxResult();
    }

}
